#include <windows.h>
#include "dxTimer.h"

dxTimer::dxTimer()
{

}

dxTimer::~dxTimer()
{

}

void dxTimer::init(int fps)
{
	QueryPerformanceFrequency(&timerFreq);
	QueryPerformanceCounter(&timeNow);
	QueryPerformanceCounter(&timePrevious);
	
	Requested_FPS=fps;

	intervalsPerFrame = ( (float)timerFreq.QuadPart / Requested_FPS );

}

int dxTimer::framesToUpdate()
{
	int framesToUpdate = 0;
	QueryPerformanceCounter(&timeNow);

	intervalsSinceLastUpdate = (float)timeNow.QuadPart - (float)timePrevious.QuadPart;
	
	framesToUpdate = (int)( intervalsSinceLastUpdate / intervalsPerFrame );

	if (framesToUpdate != 0)
	{
		QueryPerformanceCounter(&timePrevious);
	}

	return framesToUpdate;
}